package cn.kginglam.dynamic_excel.model.entity;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.kginglam.dynamic_excel.model.excel.StudentInfoImportModule;
import com.baomidou.mybatisplus.annotation.TableName;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 开放学员信息表
 * </p>
 *
 * @author Lam
 * @since 2021-09-02
 */

@TableName("student_info")
public class StudentInfo {


    private static final long serialVersionUID = 1L;

    private Long id;

    private String code;

    private String name;

    private String phone;

    private String cardNo;

    private Short cardNoType;

    private Short sex;

    private String qq;

    private String email;


    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getCardNo() {
        return cardNo;
    }

    public void setCardNo(String cardNo) {
        this.cardNo = cardNo;
    }

    public Short getCardNoType() {
        return cardNoType;
    }

    public void setCardNoType(Short cardNoType) {
        this.cardNoType = cardNoType;
    }

    public Short getSex() {
        return sex;
    }

    public void setSex(Short sex) {
        this.sex = sex;
    }

    public String getQq() {
        return qq;
    }

    public void setQq(String qq) {
        this.qq = qq;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public void transition(StudentInfoImportModule studentInfoImportModule) {
        this.cardNoType = StudentInfoCardNoTypeEnum.getType(studentInfoImportModule.getCardNoType());
        this.sex = StudentInfoSexEnum.getType(studentInfoImportModule.getSex());
        this.cardNo = studentInfoImportModule.getCardNo();
        this.name = studentInfoImportModule.getName();
        this.phone = studentInfoImportModule.getPhone();
        this.qq = studentInfoImportModule.getQq();
        this.email = studentInfoImportModule.getEmail();
    }


    public static List<StudentInfo> batchTransition(List<StudentInfoImportModule> studentInfoImportModuleList){
        List<StudentInfo> studentInfoList = new ArrayList<>();

        if(CollectionUtil.isEmpty(studentInfoImportModuleList)){
            return studentInfoList;
        }

        studentInfoImportModuleList.forEach(studentInfoImportModule -> {
            StudentInfo studentInfo = new StudentInfo();
            studentInfo.transition(studentInfoImportModule);
            studentInfo.setCode(RandomUtil.randomString(10));
            studentInfoList.add(studentInfo);
        });

        return studentInfoList;
    }


    enum StudentInfoSexEnum {
        MAN((short) 1,"男"),
        WOMAN((short)2,"女");

        private Short type;
        private String content;

        StudentInfoSexEnum(Short type, String content) {
            this.type = type;
            this.content = content;
        }


        public Short getType() {
            return type;
        }

        public void setType(Short type) {
            this.type = type;
        }

        public String getContent() {
            return content;
        }

        public void setContent(String content) {
            this.content = content;
        }

        public static Short getType(String content) {
            for (StudentInfoSexEnum typeEnum : values()) {
                if (StrUtil.equals(typeEnum.getContent(),content)) return typeEnum.getType();
            }
            return null;
        }

    }

    enum StudentInfoCardNoTypeEnum {


        IDENTITY_CARD_NO((short) 1, "身份证"),
        HK_M_T_CARD_NO((short) 2, "港澳台居民证件");


        private Short type;
        private String content;

        public Short getType() {
            return type;
        }

        public void setType(Short type) {
            this.type = type;
        }


        public String getContent() {
            return content;
        }

        public void setContent(String content) {
            this.content = content;
        }

        StudentInfoCardNoTypeEnum(Short type, String content) {
            this.type = type;
            this.content = content;
        }

        public static Short getType(String content) {
            for (StudentInfoCardNoTypeEnum typeEnum : values()) {
                if (StrUtil.equals(typeEnum.getContent(),content)) return typeEnum.getType();
            }
            return null;
        }
    }
}


